home *** CD-ROM | disk | FTP | other *** search
- package javax.swing;
-
- import java.awt.Component;
- import java.io.FilterInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InterruptedIOException;
-
- public class ProgressMonitorInputStream extends FilterInputStream {
- private ProgressMonitor monitor;
- private int nread = 0;
- private int size = 0;
-
- public ProgressMonitorInputStream(Component var1, Object var2, InputStream var3) {
- super(var3);
-
- try {
- this.size = var3.available();
- } catch (IOException var4) {
- this.size = 0;
- }
-
- this.monitor = new ProgressMonitor(var1, var2, (String)null, 0, this.size);
- }
-
- public void close() throws IOException {
- super.in.close();
- this.monitor.close();
- }
-
- public ProgressMonitor getProgressMonitor() {
- return this.monitor;
- }
-
- public int read() throws IOException {
- int var1 = super.in.read();
- if (var1 >= 0) {
- this.monitor.setProgress(++this.nread);
- }
-
- if (this.monitor.isCanceled()) {
- InterruptedIOException var2 = new InterruptedIOException("progress");
- var2.bytesTransferred = this.nread;
- throw var2;
- } else {
- return var1;
- }
- }
-
- public int read(byte[] var1) throws IOException {
- int var2 = super.in.read(var1);
- if (var2 > 0) {
- this.monitor.setProgress(this.nread += var2);
- }
-
- if (this.monitor.isCanceled()) {
- InterruptedIOException var3 = new InterruptedIOException("progress");
- var3.bytesTransferred = this.nread;
- throw var3;
- } else {
- return var2;
- }
- }
-
- public int read(byte[] var1, int var2, int var3) throws IOException {
- int var4 = super.in.read(var1, var2, var3);
- if (var4 > 0) {
- this.monitor.setProgress(this.nread += var4);
- }
-
- if (this.monitor.isCanceled()) {
- InterruptedIOException var5 = new InterruptedIOException("progress");
- var5.bytesTransferred = this.nread;
- throw var5;
- } else {
- return var4;
- }
- }
-
- public synchronized void reset() throws IOException {
- super.in.reset();
- this.nread = this.size - super.in.available();
- this.monitor.setProgress(this.nread);
- }
-
- public long skip(long var1) throws IOException {
- long var3 = super.in.skip(var1);
- if (var3 > 0L) {
- this.monitor.setProgress(this.nread = (int)((long)this.nread + var3));
- }
-
- return var3;
- }
- }
-